/**
 * Project Name:YCApiServer-Api
 * File Name:InspireController.java
 * Package Name:com.yc.music.controller.Api.auth
 * Date:2016年5月12日上午11:30:58
 * Copyright (c) 2016 
 *
 */
package com.yc.music.controller.Api.auth;

import java.util.HashMap;
import java.util.Map;

import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.music.common.context.YcContext;
import com.yc.music.model.inspire.Inspire;
import com.yc.music.service.service103.InspireService;

/**
 * 灵感记录 api
 * ClassName: InspireController <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2016年5月12日 上午11:30:58 <br/>
 *
 * @author panguixiang
 * @version 
 */
@Controller
@RequestMapping("/inspire")
public class InspireController {
	
	private static Logger logger = Logger.getLogger(InspireController.class);
	
	@Autowired
	private InspireService inspireService;
	
	/**
	 * 
	 * saveSprie:(新增灵感记录). <br/> 
	 *
	 * @author panguixiang
	 * @param spire
	 * @param binding
	 * @return
	 * @since JDK 1.7
	 */
	@ResponseBody
	@RequestMapping(value="save", method = RequestMethod.POST, produces = "application/json")
	public Map<String,Object> saveSprie(
			@Valid Inspire spire,BindingResult binding) {
		
		Map<String,Object> result  = new HashMap<String,Object>();
		try {
			result=inspireService.saveSprie(spire, binding,result);
		} catch (Exception e) {
			result.put(YcContext.CODE, 500);
			result.put(YcContext.MESSAGE, YcContext.SYS_ERROR_MSG);
			result.put(YcContext.DATA,YcContext.EMPTY_STRING);
			logger.error(e);
		}
		return result;
	}
	
	
	/**
	 * 
	 * saveSprie:(修改灵感记录). <br/> 
	 *
	 * @author panguixiang
	 * @param spire
	 * @param binding
	 * @return
	 * @since JDK 1.7
	 */
	@ResponseBody
	@RequestMapping(value="update", method = RequestMethod.POST, produces = "application/json")
	public Map<String,Object> updateSprize(
			@Valid Inspire spire,BindingResult binding) {
		
		Map<String,Object> result  = new HashMap<String,Object>();
		try {
			result=inspireService.updateSprie(spire, binding,result);
		} catch (Exception e) {
			result.put(YcContext.CODE, 500);
			result.put(YcContext.MESSAGE, YcContext.SYS_ERROR_MSG);
			result.put(YcContext.DATA,YcContext.EMPTY_STRING);
			logger.error(e);
		}
		return result;
	}
	
	/**
	 * 
	 * deleteSprie:(删除灵感记录). <br/> 
	 *
	 * @author panguixiang
	 * @param id
	 * @return
	 * @since JDK 1.7
	 */
	@ResponseBody
	@RequestMapping(value="deleteSprie",  produces = "application/json")
	public Map<String,Object> deleteSprie(
			@RequestParam("id") Long id) {
		
		Map<String,Object> result  = new HashMap<String,Object>();
		try {
			result=inspireService.deleteSprie(id,result);
		} catch (Exception e) {
			result.put(YcContext.CODE, 500);
			result.put(YcContext.MESSAGE, YcContext.SYS_ERROR_MSG);
			result.put(YcContext.DATA,YcContext.EMPTY_STRING);
			logger.error(e);
		}
		return result;
	}
	/**
	 * 
	 * detail:(灵感记录详情). <br/> 
	 *
	 * @author panguixiang
	 * @param id
	 * @return
	 * @since JDK 1.7
	 */
	@ResponseBody
	@RequestMapping(value="detail", method = RequestMethod.GET, produces = "application/json")
	public Map<String,Object> detail(
			@RequestParam("id") Long id) {
		
		Map<String,Object> result  = new HashMap<String,Object>();
		try {
			inspireService.getSprie(id, result);
		} catch (Exception e) {
			result.put(YcContext.CODE, 500);
			result.put(YcContext.MESSAGE, YcContext.SYS_ERROR_MSG);
			result.put(YcContext.DATA,YcContext.EMPTY_STRING);
			logger.error(e);
		}
		return result;
	}
}
